package thread.synchronizedtest.test02;


public class ObjectService {
    public synchronized  void objectMethodA(){
        System.out.println("run----objectMethodA");
    }
//    public void objectMethodB(){
//        synchronized (this) {
//            try {
//                for (int i = 1; i <= 10; i++) {
//                    System.out.println("synchronized thread name:"+Thread.currentThread().getName()+"-->i="+i);
//                    Thread.sleep(1000);
//                }
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
//    }
    /**
     * 用上面的那个方法执行  效果也是同样的
     * */
    public synchronized void objectMethodB(){

            try {
                for (int i = 1; i <= 10; i++) {
                    System.out.println("synchronized thread name:"+Thread.currentThread().getName()+"-->i="+i);
                    Thread.sleep(1000);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

}